<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="../fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="../js/datepicker.js"></script>
<link href="../css/datepicker.css" rel="stylesheet" type="text/css" />

<script>

function submitCompany(){
	var result = true;
	var sector = document.getElementById("sector").value;
	var industry = document.getElementById("industry").value;
	var legalName = document.getElementById("legalName").value;
	var englishName = document.getElementById("englishName").value;
	var address1 = document.getElementById("address1").value;
	var phone = document.getElementById("phone").value;
	var email = document.getElementById("email").value;
	var createDate = document.getElementById("createDate").value;	
	
	//alert(sector);
	if(sector == 0){
		jQuery("#sector_hide").html("Please choose Sector of Company");	
		result = false;
	}else{
		jQuery("#sector_hide").html("");
	}
	
	if(industry == 0){
		jQuery("#industry_hide").html("Please choose Industry of Company");	
		result = false;
	}else{
		jQuery("#industry_hide").html("");
	}
	
	if(legalName == ""){
		jQuery("#legalName_hide").html("Please enter Legal Name");	
		result = false;
	}else{
		jQuery("#legalName_hide").html("");
	}
	
	if(englishName == ""){
		jQuery("#englishName_hide").html("Please enter English Name");	
		result = false;
	}else{
		jQuery("#englishName_hide").html("");
	}
	
	if(address1 == ""){
		jQuery("#address1_hide").html("Please enter Address");	
		result = false;
	}else{
		jQuery("#address1_hide").html("");
	}
	
	if(isPhoneNumber(phone) == false){
		jQuery("#phone_hide").html("Please enter Phone Number");	
		result = false;
	}else{
		jQuery("#phone_hide").html("");
	}
	
	if(isDate(createDate) == false){
		jQuery("#createDate_hide").html("Please enter create Date");	
		result = false;
	}else{
		jQuery("#createDate_hide").html("");
	}
	
	if(isEmail(email) == false){
		jQuery("#email_hide").html("Please enter Company's Email");	
		result = false;
	}else{
		jQuery("#email_hide").html("");
	}
	
	var description = FCKeditorAPI.GetInstance("description").GetHTML(false);
	if (description.length == 0 || description == "") {
		jQuery("#description_hide").html("Please enter Company's Description");	
		result = false;
	}else{
		jQuery("#description_hide").html("");
	}
	if(result == false){
		return false;
	}
	document.createCompany.action = "doCreateCompany";
	document.createCompany.submit();
}
</script>

<form name="createCompany" action="" method="Post" enctype="multipart/form-data">
<div align="left" style="padding:10px; border:1px solid #dfdfdf;">
	<div style="font-size:20px;" align="center">create new Company</div>
	<br/>
	<table class="table_default" cellpadding="5" style="margin-left:30px;">
			<tr>
			<td width="30%"  align="right"> Sector: </td>
			<td width="3%"><span class="note">*</span></td>
			<td>
				
				<select id="sector" name="sector" class="input_default" onchange="javascript:getIndustryList();">
				<option value="0">Chọn Nhóm Ngành</option>
				<c:forEach items="${listSector}" var="sectorItem" varStatus="status">
					<option value="${sectorItem.sectorId}">${sectorItem.sectorName }</option>
				</c:forEach>		
				</select>
			</td>
		</tr>
		<tr><td></td><td></td><td><div id="sector_hide" class="note"></div></td></tr>
		<tr>
			<td  align="right"> Industry: </td>
			<td width="3%"><span class="note">*</span></td>
			<td>
				<select id="industry" name="industry" class="input_default">
				<option value="0">Chọn Ngành</option>						
				</select>
			</td>
		</tr>
		<tr><td></td><td></td><td><div id="industry_hide" class="note"></div></td></tr>
		<tr>
			<td  align="right"> Legal Name: </td>
			<td width="3%"><span class="note">*</span></td>
			<td>
				<input type="text" id="legalName" name="legalName" class="input_default" style="width:500px;"/>
			</td>
		</tr>
		<tr><td></td><td></td><td><div id="legalName_hide" class="note"></div></td></tr>
		<tr>
			<td  align="right"> English Name: </td>
			<td width="3%"><span class="note">*</span></td>
			<td>
				<input type="text" id="englishName" name="englishName" class="input_default" style="width:500px;"/>
			</td>
		</tr>
		<tr><td></td><td></td><td><div id="englishName_hide" class="note"></div></td></tr>
		<tr>
			<td  align="right"> Short Name: </td>
			<td width="3%"></td>
			<td>
				<input type="text" id="shortName" name="shortName" class="input_default" style="width:500px;"/>
			</td>
		</tr>
		
		<tr>
			<td  align="right"> Address: </td>
			<td width="3%"><span class="note">*</span></td>
			<td>
				<input type="text" id="address1" name="address1" class="input_default" style="width:500px;"/>
			</td>
		</tr>
		<tr><td></td><td></td><td><div id="address1_hide" class="note"></div></td></tr>
		<tr>
			<td  align="right"> Phone: </td>
			<td width="3%"><span class="note">*</span></td>
			<td>
				<input type="text" id="phone" name="phone" class="input_default"/>
			</td>
		</tr>
		<tr><td></td><td></td><td><div id="phone_hide" class="note"></div></td></tr>
		<tr>
			<td  align="right"> Fax: </td>
			<td width="3%"></td>
			<td>
				<input type="text" id="fax" name="fax" class="input_default"/>
			</td>
		</tr>
		<tr>
			<td  align="right"> Email: </td>
			<td width="3%"><span class="note">*</span></td>
			<td>
				<input type="text" id="email" name="email" class="input_default"/>
			</td>
		</tr>
		<tr><td></td><td></td><td><div id="email_hide" class="note"></div></td></tr>
		<tr>
			<td  align="right"> Website: </td>
			<td width="3%"></td>
			<td>
				<input type="text" id="website" name="website" class="input_default"/>
			</td>
		</tr>		
		<tr>
			<td  align="right"> Create Date: </td>
			<td width="3%"><span class="note">*</span></td>
			<td>
				<input type="text" class="w16em dateformat-d-sl-m-sl-Y" id="createDate" name="createDate"/><span> &nbsp; Ex: 31/12/2011</span>
			</td>
		</tr>
		<tr><td></td><td></td><td><div id="createDate_hide" class="note"></div></td></tr>
	</table>
	<table width="100%">
		<tr><td align="left">Descreption : <span class="note">*</span></td></tr>
		<tr><td><div id="description_hide" class="note"></div></td></tr>
		<tr>
			
			<td><div style="padding:10px;">
				<textarea id="description" name="description" cols="80" rows="24" wrap="virtual"/>
				</textarea>
				</div>
			</td>
		</tr>
	</table>
	<br>
</div>
</form>
<script type="text/javascript">
    var name = 'description';
    //var base_url = window.location.href;
   // base_url = base_url.substring(0,base_url.indexOf('/tag.'));
    var editor = new FCKeditor(name,'100%','400','Default') ;
    //editor.BasePath= 'fckeditor/';
    //editor.Width = '900px';
    //editor.Height = '400px'; 
	
    editor.ReplaceTextarea() ;
</script>
<div align="center">
	<input type="button" value="Create" class="bt_detail" onclick="javascript:submitCompany();" />
	<input type="button" value="Clear" class="bt_detail" onclick="javascript:clearContent();" />
</div>
